<template>
  <div>
    <!--修改用户对话框 -->
    <el-dialog title="修改用户" v-model="dialogVisible" :close-on-click-modal="false" @close="resetForm">
      <el-form :model="form" ref="modifyForm">
        <el-form-item label="姓名" prop="name" label-width="80px">
          <el-input v-model="form.name" placeholder="请输入姓名"></el-input>
        </el-form-item>
        <el-form-item label="工号" prop="code" label-width="80px">
          <el-input v-model="form.code" placeholder="请输入工号"></el-input>
        </el-form-item>
        <el-form-item label="手机号" prop="mobile" label-width="80px">
          <el-input v-model="form.mobile" placeholder="请输入手机号"></el-input>
        </el-form-item>
        <el-form-item label="邮箱" prop="email" label-width="80px">
          <el-input v-model="form.email" placeholder="请输入邮箱"></el-input>
        </el-form-item>
        <el-form-item label="性别" prop="sex" label-width="80px">
          <el-radio-group v-model="form.sex">
            <el-radio-button label="男" value="1"/>
            <el-radio-button label="女" value="2"/>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="年龄" prop="age" label-width="80px">
          <el-input v-model="form.age" placeholder="请输入年龄"></el-input>
        </el-form-item>
      </el-form>
      <span class="dialog-footer">
				<el-button @click="resetForm">重填</el-button>
				<el-button type="primary" @click="submitForm">修改</el-button>
			</span>
    </el-dialog>
  </div>
</template>
<script setup>
import {ElMessage} from 'element-plus';
import {reactive, ref, toRefs} from 'vue';
import {nations, polities} from '@/config/index.js';

const data = reactive({
  dialogVisible: false, // 控制对话框的显示状态
  //表单字段
  form: {
    userId: 3,
    name: '张伟',
    code: 'S003',
    mobile: '13800000002',
    email: 'zhang138@163.com',
    sex: 1,
    age: 28,
    status: 1,
    userType: 2,
  },
});
//创建学生表单组件实例
let modifyForm = ref(null);
let {
  dialogVisible,
  form
} = toRefs(data);
//提交form表单
const submitForm = () => {
  modifyForm.value.validate((valid) => {
    if (valid) {
      ElMessage({message: '提交成功!', type: 'success'});
      data.dialogVisible = false; // 关闭对话框
      // 这里可以添加提交表单到后台的逻辑
      console.info(data.form)
    } else {
      ElMessage({message: '提交失败!', type: 'error'});
      return false;
    }
  });
};

//重置表单
const resetForm = () => {
  modifyForm.value.resetFields();
};
//暴露dialogVisible,父组件可以直接使用
defineExpose({
  dialogVisible,
});
</script>


<style scoped>
/* 样式可以根据需要自定义 */
</style>